home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F26906_CreateEmployeeAttributes.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  2.6 KB  |  76 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Category:       XSLT
  4.   Sub-category:   xsl:attribute
  5.   Author:         David Silverlight
  6.                   HeadGeek@xmlpitstop.com
  7.   Created:        2001-05-16
  8.   Description:-
  9.     This stylesheet processes a set of XML elements and uses the
  10.     xsl:attribute element to generate a new xml file containing
  11.     atrributes from the original xml document as well as new
  12.     attributes created with xslt functions like a
  13.     substring-before, substring-after and others.
  14. ================================================================ -->
  15. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  16. <xsl:output method="xml"/>
  17.  
  18. <!-- Template for root rule -->
  19. <xsl:template match="/">
  20.     <xsl:apply-templates/>
  21. </xsl:template>
  22.  
  23.  
  24. <!-- Template for "employees" elements -->
  25. <xsl:template match="employees">
  26.     <!--This stylesheet processes a set of XML elements and 
  27.     uses the xsl:attribute element to generate a new xml file containing
  28.     atrributes from the original xml document as well as new attributes
  29.     that are created through variable.-->
  30.  
  31.     <!-- Generate the "bademployees" root element -->
  32.     <xsl:element name="bademployees" >
  33.         
  34.  
  35.  
  36.     <xsl:for-each select="employee[department='Sales']" >
  37.  
  38.         <xsl:sort select="department" order="ascending" />
  39.         <xsl:element name="employee" >
  40.  
  41.             <!-- Create of the department attribute.  -->
  42.             <xsl:attribute name="department" >
  43.                 <!-- Set the value of the attribue based on the department -->
  44.                 <xsl:value-of select="department" />
  45.             </xsl:attribute>
  46.  
  47.  
  48.             <!-- Here we are creating an attribute that is a variation from 
  49.             the original source document.  In this example we are breaking
  50.             up employee name and creating two new attributes from it (firstname and lastname) -->
  51.             <xsl:attribute name="firstname">
  52.                 <xsl:value-of select="substring-before(employeename, ' ')" />
  53.             </xsl:attribute>
  54.  
  55.  
  56.             <!-- We can also create and set variables to be used as our attribute
  57.                 values. Note: We are doing the same as with firstname
  58.                  but just accomplishing it with the use of an xsl:varialbe. -->
  59.             <xsl:attribute name="lastname">
  60.                  <xsl:variable name="lastname" select="substring-after(employeename, ' ')" />
  61.                 <xsl:value-of select="$lastname" />
  62.             </xsl:attribute>
  63.  
  64.             <!-- Here we are creating a new attribute set to a value that we define -->
  65.             <xsl:attribute name="new" >
  66.                 <xsl:value-of select="'new and exciting attribute'" />
  67.             </xsl:attribute>
  68.  
  69.         </xsl:element>
  70.     </xsl:for-each>
  71.     </xsl:element>
  72. </xsl:template>
  73.  
  74.  
  75.  
  76. </xsl:stylesheet>